GATE Exam  >  GATE Questions  >  Consider the following recursive function fin... Start Learning for Free
Consider the following recursive function find.
int find (int A[], int n)
{
int sum=0;
if(n==0) return0;
sum = find(A, n-1)
if (A[n-1]<0) sum=sum+1;
return sum;
}
Q. What is the worst case running time above function find (A[], n) when array A has 0 to n-1 elements?
  • a)
    O(1)
  • b)
    O(log n)
  • c)
    O(n)
  • d)
    O(n2)
Correct answer is option 'C'. Can you explain this answer?
Verified Answer
Consider the following recursive function find.int find (int A[], int ...
Recurrence relation for the function find:
F(n)=0; if n=0
=F(n-1)+1 ;n>0
Time complexity of F(n)=O(n)
View all questions of this test
Most Upvoted Answer
Consider the following recursive function find.int find (int A[], int ...
It seems that the code provided is incomplete and missing the closing brace for the if statement. However, based on the given code snippet, it appears to be attempting to find the sum of elements in an array recursively.

Here is a corrected version of the code:

```cpp
int find(int A[], int n) {
int sum = 0;
if (n == 0)
return 0;
sum = find(A, n-1) + A[n-1];
return sum;
}
```

Explanation:
- The function `find` takes an integer array `A` and an integer `n` as parameters.
- It initializes a variable `sum` to 0.
- If `n` is 0 (the base case), it returns 0.
- Otherwise, it calls the function `find` recursively with the array `A` and `n-1` as arguments, and assigns the returned value to `sum`.
- It then adds the value of `A[n-1]` to `sum`.
- Finally, it returns `sum`, which represents the sum of all elements in the array.
Explore Courses for GATE exam
Consider the following recursive function find.int find (int A[], int n){int sum=0;if(n==0) return0;sum = find(A, n-1)if (A[n-1]<0) sum=sum+1;return sum;}Q. What is the worst case running time above function find (A[], n) when array A has 0 to n-1 elements?a)O(1)b)O(log n)c)O(n)d)O(n2)Correct answer is option 'C'. Can you explain this answer?
Question Description
Consider the following recursive function find.int find (int A[], int n){int sum=0;if(n==0) return0;sum = find(A, n-1)if (A[n-1]<0) sum=sum+1;return sum;}Q. What is the worst case running time above function find (A[], n) when array A has 0 to n-1 elements?a)O(1)b)O(log n)c)O(n)d)O(n2)Correct answer is option 'C'. Can you explain this answer? for GATE 2024 is part of GATE preparation. The Question and answers have been prepared according to the GATE exam syllabus. Information about Consider the following recursive function find.int find (int A[], int n){int sum=0;if(n==0) return0;sum = find(A, n-1)if (A[n-1]<0) sum=sum+1;return sum;}Q. What is the worst case running time above function find (A[], n) when array A has 0 to n-1 elements?a)O(1)b)O(log n)c)O(n)d)O(n2)Correct answer is option 'C'. Can you explain this answer? covers all topics & solutions for GATE 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider the following recursive function find.int find (int A[], int n){int sum=0;if(n==0) return0;sum = find(A, n-1)if (A[n-1]<0) sum=sum+1;return sum;}Q. What is the worst case running time above function find (A[], n) when array A has 0 to n-1 elements?a)O(1)b)O(log n)c)O(n)d)O(n2)Correct answer is option 'C'. Can you explain this answer?.
Solutions for Consider the following recursive function find.int find (int A[], int n){int sum=0;if(n==0) return0;sum = find(A, n-1)if (A[n-1]<0) sum=sum+1;return sum;}Q. What is the worst case running time above function find (A[], n) when array A has 0 to n-1 elements?a)O(1)b)O(log n)c)O(n)d)O(n2)Correct answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for GATE. Download more important topics, notes, lectures and mock test series for GATE Exam by signing up for free.
Here you can find the meaning of Consider the following recursive function find.int find (int A[], int n){int sum=0;if(n==0) return0;sum = find(A, n-1)if (A[n-1]<0) sum=sum+1;return sum;}Q. What is the worst case running time above function find (A[], n) when array A has 0 to n-1 elements?a)O(1)b)O(log n)c)O(n)d)O(n2)Correct answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the following recursive function find.int find (int A[], int n){int sum=0;if(n==0) return0;sum = find(A, n-1)if (A[n-1]<0) sum=sum+1;return sum;}Q. What is the worst case running time above function find (A[], n) when array A has 0 to n-1 elements?a)O(1)b)O(log n)c)O(n)d)O(n2)Correct answer is option 'C'. Can you explain this answer?, a detailed solution for Consider the following recursive function find.int find (int A[], int n){int sum=0;if(n==0) return0;sum = find(A, n-1)if (A[n-1]<0) sum=sum+1;return sum;}Q. What is the worst case running time above function find (A[], n) when array A has 0 to n-1 elements?a)O(1)b)O(log n)c)O(n)d)O(n2)Correct answer is option 'C'. Can you explain this answer? has been provided alongside types of Consider the following recursive function find.int find (int A[], int n){int sum=0;if(n==0) return0;sum = find(A, n-1)if (A[n-1]<0) sum=sum+1;return sum;}Q. What is the worst case running time above function find (A[], n) when array A has 0 to n-1 elements?a)O(1)b)O(log n)c)O(n)d)O(n2)Correct answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the following recursive function find.int find (int A[], int n){int sum=0;if(n==0) return0;sum = find(A, n-1)if (A[n-1]<0) sum=sum+1;return sum;}Q. What is the worst case running time above function find (A[], n) when array A has 0 to n-1 elements?a)O(1)b)O(log n)c)O(n)d)O(n2)Correct answer is option 'C'. Can you explain this answer? tests, examples and also practice GATE tests.
Explore Courses for GATE exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev